package www.cskaoyan.com.dao;

import www.cskaoyan.com.bean.ClassManager;
import www.cskaoyan.com.bean.Group;
import www.cskaoyan.com.dao.JDBCUtils.ConnectionPool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GroupManagerDao {

    Connection connection;

    public List<Group> getClassList() throws SQLException {
        connection = ConnectionPool.getConnection();


        String sql = "select *  from `group` ";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();


        List<Group> list = new ArrayList<>();
        while (resultSet.next()){

            int id = resultSet.getInt(1);
            String groupName  = resultSet.getString(2);


            Group group = new Group();
            group.setId(id);
            group.setGroupName(groupName);

            list.add(group);
        }

        return list;
    }
}
